package cc.rico.util;

import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;

/**
 * Created by rico on 2018/8/19.
 */
public class ZkUtil {
    public static final int DEFAULT_TIMEOUT = 4000;

    public ZooKeeper createConnection(String host, String port, Watcher watcher) throws IOException {
        String connectString = host.concat(":").concat(port);
        ZooKeeper zk = new ZooKeeper(connectString, DEFAULT_TIMEOUT, watcher);

        return zk;
    }

    public static void close(ZooKeeper zk) throws InterruptedException {
        if(zk != null) {
            zk.close();
        }
    }
}
